package com.example.maze;

import tw.fc.agui.*;
import android.graphics.Color;

/* 這版的雷達圖起點與終點分別固定在左上角及
     右下角, 若往後改變起點與終點位置, 那麼此
     雷達圖內部要整個重寫.     
*/
public class Radar extends GraphicObj {
   private final MuV2D org;
   private final MuV2D entryOrg; 
   private final MuV2D exitOrg; 
   private final MuV2D wh; 
   private final MuV2D offset;
   
   private MuV2D currentPos= new MuV2D();
   
   public Radar() {
      int sw= DataSet.screenWidth, sh= DataSet.screenHeight;
            
      this.wh      = new MuV2D(200, 200);
      //[ 使雷達圖畫在正中間
      this.org     = new MuV2D(sw/2, sh/2).subBy(wh.mul(0.5));
      //[ entryOrg值同 org.
      this.entryOrg= new MuV2D(org);      
      this.offset  = new MuV2D(this.wh.ix()/DataSet.MAZE_N,
                               this.wh.iy()/DataSet.MAZE_M);      
      this.exitOrg= new MuV2D(this.org.add(wh).sub(offset));
   }
   
   public void setOrg(int x, int y) {
      this.org.setBy(x,y);      
      this.entryOrg.setBy(org);
      this.exitOrg.setBy(this.org.add(wh).sub(offset));
   }

   @Override
   public void paintTo(GrCanvas g) {
      int oldColor= g.getColor();
      //[ 底圖
      g.setColor(Color.argb(99,255,255,255));      
      g.fillRect(org.ix(), org.iy(), wh.ix(), wh.iy());
      //[ 起點
      g.setColor(Color.BLUE);
      g.fillRect(entryOrg.ix(), entryOrg.iy(), 
                      offset.ix(), offset.iy());
      //[ 終點
      g.setColor(Color.RED);
      g.fillRect(exitOrg.ix(), exitOrg.iy(), 
                      offset.ix(), offset.iy());
      //[ 玩家位置
      g.setColor(Color.GREEN);
      currentPos.setBy(org.add(new ImuV2D(offset.ix()*DataSet.myPosN, 
                                          offset.iy()*DataSet.myPosM)            
                              )
                      );
      g.fillRect(currentPos.ix(), currentPos.iy(), 
                      offset.ix(), offset.iy());
      //[ 採(x,y) 而非(m,n)
      g.setColor(Color.BLACK);
      float oldTextSize= g.getTextSize();
      g.setTextSize(16);
      g.drawString("distance: ("+(DataSet.MAZE_N-DataSet.myPosN-1)+","+
                                 (DataSet.MAZE_M-DataSet.myPosM-1)+")",
                   org.ix(), org.iy()+wh.mul(1.2).iy());
      g.setTextSize(oldTextSize);
      g.setColor(oldColor);
   }

}
